package it.fuesi.synoutils.constants;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by pascotto on 20/10/14.
 */
public enum ApiErrorCode {

    NoEndpoint(-1, "Endpoint not set"),
    UnkownError(100, "Unknown error"),
    InvalidParameter(101, "Invalid Parameter"),
    ApiNotExists(102, "The requested API does not exist"),
    MethodNotExists(103, "The requested method does not exist"),
    VersionNotSupported(104, "The requested version does not support the functionality"),
    InvalidPermission(105, "The logged in session does not have permission"),
    SessionTimeout(106, "Session timeout"),
    DuplicateLogin(107, "Session interrupted by duplicate login"),
    NoSuchAccountOrIncorrectPassword(400, "No such account or incorrect password"),
    GuestAccountDisabled(401, "Guest account disabled"),
    AccountDisabled(402, "Account disabled"),
    WrongPassword(403, "Wrong password"),
    PermissionDenied(404, "Permission denied"),
    InvalidUserFileOperation(405, "Invalid user and group does this file operation"),
    CantGetUserInformation(406, "Can’t get user/group information from the account server"),
    OperationNotPermitted(407, "Operation not permitted"),
    NoSuchFileOrDirectory(408, "No such file or directory"),
    NonSupportedFileSystem(409, "Non-supported file system"),
    ConnectionFailure(410, "Failed to connect internet-based file system (ex: CIFS)"),
    ReadOnlyFileSystem(411, "Read-only file system"),
    FileNameTooLongNonEnc(412, "Filename too long in the non-encrypted file system"),
    FileNameTooLongEnc(413, "Filename too long in the encrypted file system"),
    FileAlreadyExists(414, "File already exists"),
    DiskQuotaExceeded(415, "Disk quota exceeded"),
    NoSpaceLeftOnDevice(416, "No space left on device"),
    InputOutputError(417, "Input/output error"),
    IllegalNameOrPath(418, "Illegal name or path"),
    IllegalFileName(419, "Illegal file name"),
    IllegalFileNameOnFAT(420, "Illegal file name on FAT file system"),
    DeviceOrResourceBusy(421, "Device or resource busy"),
    NoSuchTask(599, "No such task of the file operation"),
    retry(666, "Retry"),
    copyError0(1000,"Failed to copy files/folders. More information in <errors> object" ),
    copyError1(1001,"Failed to move files/folders. More information in <errors> object"),
    copyError2(1002,"An error occurred at the destination. More information in <errors> object"),
    copyError3(1003,"Cannot overwrite or skip the existing file because no overwrite parameter is given"),
    copyError4(1004,"File cannot overwrite a folder with the same name, or folder cannot overwrite a file with the same name"),
    copyError5(1006,"Cannot copy/move file/folder with special characters to a FAT32 file system"),
    copyError6(1007,"Cannot copy/move a file bigger than 4G to a FAT32 file system"),
    createFolderError1(1100, "Failed to create a folder. More information in <errors> object"),
    createFolderError2(1101, "he number of folders to the parent folder would exceed the system limitation"),
    renameError1(1200, "Failed to rename it. More information in <errors> object");


    private int errorCode;
    private String errorMessage;

    public int getErrorCode(){return this.errorCode;}
    public String getErrorMessage(){return this.errorMessage;}

    ApiErrorCode(int errorCode, String errorMessage){
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    private static final Map<Integer, ApiErrorCode> mapping = getMapping();

    private static final Map<Integer, ApiErrorCode> getMapping(){
        final Map<Integer, ApiErrorCode> map = new HashMap<Integer, ApiErrorCode>();
        for(ApiErrorCode a : ApiErrorCode.values()){
            map.put(a.errorCode, a);
        }
        return map;
    }

    public static final ApiErrorCode get(int code){
        if(mapping.containsKey(code))
            return mapping.get(code);
        else
            return ApiErrorCode.UnkownError;
    }

    public static final ApiErrorCode get(String code){

        return get(Integer.parseInt(code));
    }

}
